package structure.privilege.basic;

import structure.heap.basic.MyBinaryHeap;

import java.util.Comparator;

/**
 * 项目名称: god
 * 包 名 称: structure.privilege.basic
 * 类 名 称: MyPriorityQueue
 * 类 描 述: TODO
 * 创建时间: 2020/6/19 8:39 下午
 * 创 建 人: Justice
 */
public class MyPriorityQueue<E> {
    // 利用二叉堆实现优先队列
    private MyBinaryHeap<E> heap;

    // 通过comparator自定义优先级高低
    public MyPriorityQueue(Comparator<E> comparator) {
        heap = new MyBinaryHeap<>(comparator);
    }

    public MyPriorityQueue() {
        this(null);
    }

    public int size() {
        return heap.size();
    }

    public boolean isEmpty() {
        return heap.isEmpty();
    }

    public void clear() {
        heap.clear();
    }

    public void enQueue(E element) {
        heap.add(element);
    }

    public E deQueue() {
        return heap.remove();
    }

    public E front() {
        return heap.get();
    }
}
